<template>
  <el-dialog v-model="dialogVisible" title="红冲发票" width="500" :before-close="handleClose">
    <el-form :model="formInline" label-width="100">
      <el-form-item label="订单流水号">
        <el-input v-model="formInline.ddlsh" disabled clearable />
      </el-form-item>
      <el-form-item label="作废人">
        <el-input v-model="formInline.zfr" disabled clearable />
      </el-form-item>
      <el-form-item label="作废原因">
        <el-select v-model="formInline.zfyy" placeholder="请输入作废原因">
          <el-option label="开票有误" value="开票有误" />
          <el-option label="服务终止" value="服务终止" />
          <el-option label="销货退回" value="销货退回" />
          <el-option label="其他" value="其他" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="save" :loading="loading">
          确 认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import useCounterStore from "@/store/counter";
const counter = useCounterStore();
const instance = getCurrentInstance();
const { proxy } = getCurrentInstance();
const emit = defineEmits(["fatherMethod"]);

let dialogVisible = ref(false);
let loading = ref(false);
let formInline = ref({
  ddlsh: "",
  zfr: "",
  zfyy: "",
});

function open(ddlsh) {
  formInline.value.ddlsh = ddlsh;
  formInline.value.zfr = counter.updateUser;
  dialogVisible.value = true;
}

async function save() {
  try {
    loading.value = true;
    if (!formInline.value.zfyy)
      return proxy.$utils.showToast("请选择作废原因", 0);
    await proxy.$apis.invoiceCancel(formInline.value);
    proxy.$utils.showToast("红冲发票成功");
    handleClose();
  } catch (error) {
  } finally {
    loading.value = false;
  }
}

function handleClose() {
  formInline.value = {
    ddlsh: "",
    zfr: "",
    zfyy: "",
  };
  emit("fatherMethod"); //列表重新加载
  dialogVisible.value = false;
}

defineExpose({
  open,
});
</script>



<style lang="scss" scoped>
.container {
}
</style>